import { queryWarehouseRegionList, queryWarehouseAisleList, queryWarehouseEnableList, queryImplantList,queryPurchaseList } from '@/api/warehouse.js'
import { querySupplierList } from '@/api/supplier.js'
import Vue from 'vue'
const store = {
  state: {
    region: {},
    aisle: {},
    enableWarehouse: {},
    supplier: {},
    implant:{},
    purchase:{},
  },
  mutations: {
    async getRegion(state) {
      try {
        const r = await queryWarehouseRegionList({ pageNo: 1, pageSize: 1000 })
        r.result.records.forEach(e => {
          Vue.set(state.region, e.id, e.name)
        })
      } catch (_) {}
    },
    async getAisle(state) {
      try {
        const r = await queryWarehouseAisleList({ pageNo: 1, pageSize: 1000 })
        r.result.records.forEach(e => {
          Vue.set(state.aisle, e.id, e.name)
        })
      } catch (_) {}
    },
    async getEnableWarehouse(state) {
      try {
        const r = await queryWarehouseEnableList({ pageNo: 1, pageSize: 1000 })
        r.result.records.forEach(e => {
          Vue.set(state.enableWarehouse, e.id, { text: e.name })
        })
      } catch(_) {}
    },
    async getImplantList(state) {
      try {
        const r = await queryImplantList({ pageNo: 1, pageSize: 1000 })
        r.result.records.forEach(e => {
          Vue.set(state.implant, e.id, { text: e.name })
        })
      } catch(_) {}
    },
    async getPurchaseList(state) {
      try {
        const r = await queryPurchaseList({ pageNo: 1, pageSize: 1000 })
        console.log(r);
        r.result.records.forEach(e => {
          Vue.set(state.purchase, e.id, { text: e.name })
        })
        console.log(state.purchase);
      } catch(_) {}
    },
    async getSupplier(state) {
      try {
        const r = await querySupplierList({ pageNo: 1, pageSize: 1000 })
        r.result.records.forEach(e => {
          Vue.set(state.supplier, e.id, { text: e.name })
        })
      } catch (_) {}
    }
  },
  actions: {

  }
}

export default store